<@>layout("/common/default.html"){
<div style="padding: 10px">
    <form class="layui-form" id="userMail-data">
        <!--<button type="button" onclick="addDiv();" class="layui-btn layui-btn-normal"-->
        <!--style="position: relative;left: 40px;height: 30px;line-height: 30px;">+-->
        <!--</button>-->
        <!--<div id="content-data" style="position: relative;left: 10px;">-->
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱名称：</label>
            <div class="layui-input-block">
                <input type="text" lay-verify="required|email" id="mail" class="layui-input" name="mail"
                       value=""
                       style="width: 95%">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">协议类型：</label>
            <div class="layui-input-block" style="width: 73%">
                <select name="type" id="type" lay-filter="aihao" lay-verify="required">
                    <option value=""></option>
                    <option value="SMTP">SMTP</option>
                    <option value="POP3">POP3</option>
                    <option value="IMAP">IMAP</option>
                    <option value="MIME">MIME</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱类型：</label>
            <div class="layui-input-block" style="width: 73%">
                <select name="mailService" id="mailService" lay-filter="aihao" lay-verify="required">
                    <option value=""></option>
                    <option value="smtp.qq.com">腾讯邮箱</option>
                    <option value="smtp.163.com">网易邮箱</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">账号：</label>
            <div class="layui-input-block">
                <input type="text" lay-verify="required" id="login" class="layui-input" name="login"
                       value=""
                       style="width: 95%">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码：</label>
            <div class="layui-input-block">
                <input type="text" lay-verify="required" id="password" class="layui-input" name="password"
                       value=""
                       style="width: 95%">
            </div>
        </div>
        <div class="layui-form-item" style="text-align: center">
            <input type="hidden" name="userId" id="userId" value="${userId}">
            <button type="button" class="layui-btn" lay-submit=""
                    lay-filter="editMail">提交
            </button>
        </div>

    </form>
</div>
<!--<div id="mailHtml" style="display: none">-->
<!--<div class="layui-form-item">-->
<!--<label class="layui-form-label">邮箱名称：</label>-->
<!--<div class="layui-input-block">-->
<!--<input type="text" lay-verify="required" class="layui-input" name="userMails[%].mail" value=""-->
<!--style="width: 95%">-->
<!--</div>-->
<!--</div>-->
<!--</div>-->
<script>
    var layer;
    var form;
    $(function () {
        layui.use(['layer', 'form'], function () {
            layer = layui.layer;
            form = layui.form;
        });
        var userId = $('#userId').val();
        $.cajax('${ctxPath}/ajax/userpermission/user/userMail?userId=' + userId, null, function (r) {
            var code = r.code;
            var msg = r.msg;
            var data = r.data;
            console.info(data)
            if (code == '1') {
                if (data) {
                    $('#mail').val(data.mail);
                    $('#type').val(data.type);
                    $('#login').val(data.login);
                    $('#password').val(data.password);
                    $('#mailService').val(data.mailService);
                    form.render('select'); //刷新select选择框渲染
                    $.msg(msg, function () {
                    }, code);
                }
            } else {
                $.msg(msg, function () {
                }, 2);
            }
        });
    });

    //    function addDiv() {
    //        var html = $('#mailHtml').html();
    //        html = html.replace(/\%/g, num);
    //        $('#content-data').append(html);
    //        num++;
    //    }
    //提交
    layui.use("form", function () {
        var form = layui.form;
        form.on('submit(editMail)', function () {
            $.cajax('${ctxPath}/ajax/userpermission/user/saveUserMail', $('#userMail-data').serialize(), function (r) {
                var code = r.code;
                var msg = r.msg;
                if (code == '1') {
                    $.msg(msg, function () {
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    }, code);
                } else {
                    $.msg(msg, function () {
                    }, 2);
                }
            });
        });
    })
</script>
<@>}